



	
			**	**	**	**	**	**	**	**	**	**	**	**	**
			**	**	**	**	**	**	**	**	**	**	**	**	**
			**	**	**	**	**	**	**	**	**	**	**	**	**
	


*-------------------------------------------------------------------------------
* 1970s–1990
*-------------------------------------------------------------------------------


foreach year in 1975 1981 1990 {


* Encuestas de hogares por muestreo (EHPM)
use "data/inputs/EHPM_`year'_1.dta", clear


* Nivel alcanzado
* For NGA codes, see NuevoManualV3.0.doc

gen nivel_alcanzado = "MenosDePrimaria" if nga == 0 | nga == 1 | (nga == 2 & ultgrado < 6)

replace nivel_alcanzado = "Primaria" if (nga == 2 & ultgrado >= 6 & ultgrado ~= .) /// /* At least six years of primary */
									  | (nga >= 3 & nga <= 22 & ultgrado < 5) /* Or < 5 years of educación media */

replace nivel_alcanzado = "Bachiller" if (nga >= 3 & nga <= 22 & ultgrado >= 5 & ultgrado ~= .) /// /* At least five years of high school */
									  |  (nga >= 23 & nga <= 69 & ultgrado < 5) /* Or < 5 years of university */

replace nivel_alcanzado = "Licenciado" if (nga >= 23 & nga <= 69 & ultgrado >= 5 & ultgrado ~= .)	
								  
tab nivel_alcanzado if edad >= 18 [aw=peso]


* collapse
keep if edad >= 18 & edad ~= .
gen count = 1
collapse (sum) count [fw=peso], by(nivel_alcanzado)
replace nivel = "Missing" if nivel == ""

* proportions
gen year = `year'
reshape wide count, i(year) j(nivel, string)
egen total = rowtotal(count*)
foreach var of varlist count* {
	gen p`var' = `var' / total
	}
keep year p*
renvars p*, predrop(6)


* save
order year MenosDe Primaria Bach Lic
tempfile eh`year'
save `eh`year''

}

	
			**	**	**	**	**	**	**	**	**	**	**	**	**
			**	**	**	**	**	**	**	**	**	**	**	**	**
			**	**	**	**	**	**	**	**	**	**	**	**	**
	


*-------------------------------------------------------------------------------
* 2001
*-------------------------------------------------------------------------------

use "data/inputs/EHPM_2001_2.dta", clear

* define categories
gen nivel_alcanzado = "MenosDePrimaria" if eduniv == 1 | eduniv == 2
replace nivel_alcanzado = "Primaria" if eduniv == 3 | eduniv == 5 /* ASK FROD ABOUT THIS */
replace nivel_alcanzado = "Bachiller" if eduniv == 4
replace nivel_alcanzado = "Licenciado" if eduniv == 6
replace nivel_alcanzado = "N/A" if eduniv < 0

* collapse
keep if edad >= 18 & edad ~= .
gen count = 1
collapse (sum) count [fw=peso], by(nivel_alcanzado)
replace nivel = "Missing" if nivel == "N/A"

* proportions
gen year = 2001
reshape wide count, i(year) j(nivel, string)
egen total = rowtotal(count*)
foreach var of varlist count* {
	gen p`var' = `var' / total
	}
keep year p*
renvars p*, predrop(6)

* save
order year MenosDe Primaria Bach Lic
tempfile eh2001
save `eh2001'

	
			**	**	**	**	**	**	**	**	**	**	**	**	**
			**	**	**	**	**	**	**	**	**	**	**	**	**
			**	**	**	**	**	**	**	**	**	**	**	**	**
	


*-------------------------------------------------------------------------------
* append all
*-------------------------------------------------------------------------------

clear
foreach year in 1975 1981 1990 2001 {
	append using `eh`year''	
}


* End of subfile
